package com.mypage.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudcc.mobile.R;
import com.mypage.bean.ConvertState;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/5 0005.
 */

public class NewConvertAdapter extends BaseAdapter {


    private List<ConvertState.State> mList;
    private Context context;
    private static Map<Integer, Boolean> isSclete;
    private String mStr;

    public NewConvertAdapter(Context mContext, List<ConvertState.State> list, String state) {
        this.mList = list;
        this.context = mContext;
        this.mStr = state;
        setCheckBox();
    }

    private void setCheckBox() {
        isSclete = new HashMap<>();
        for (int i = 0; i < mList.size(); i++) {
            isSclete.put(i, false);
        }
    }

    @Override
    public int getCount() {
        return mList.isEmpty() ? 0 : mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder h = null;
        if (view == null) {
            h = new ViewHolder();
            view = View.inflate(context, R.layout.aconvert_pop_item, null);
            h.textText = (TextView) view.findViewById(R.id.textText);
            h.imgYes = (ImageView) view.findViewById(R.id.imgYes);
            view.setTag(h);
        } else {
            h = (ViewHolder) view.getTag();
        }
        h.textText.setText(mList.get(i).codevalue);

        if (getChck(i)) {
            h.imgYes.setVisibility(View.VISIBLE);
        } else {
            h.imgYes.setVisibility(View.INVISIBLE);
        }
        if (mStr.contains("关闭")||mStr.contains("Closed")){
            h.imgYes.setVisibility(View.VISIBLE);
        }else{
            h.imgYes.setVisibility(View.INVISIBLE);
        }
        return view;
    }

    class ViewHolder {
        TextView textText;
        ImageView imgYes;
    }

    public static void setChck(int i, Boolean b) {

        isSclete.put(i, b);
    }

    public static Boolean getChck(int i) {

        return isSclete.get(i);
    }


}
